package com.five.wisdomEat.service;

import com.five.wisdomEat.entity.Dishes;
import com.five.wisdomEat.entity.ResponseMessage;
import com.five.wisdomEat.mapper.DishesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DishesService {
    @Autowired
    private DishesMapper mapper;

    public ResponseMessage getDishesAll(String bNumber){
        ResponseMessage message = new ResponseMessage();
        message.setData(mapper.selectDishesList(bNumber));
        message.setMessage("查询成功");
        message.setSuccess(true);
        message.setTotal(message.getData().size());
        return message;
    };

    public ResponseMessage insertDishes(Dishes dishes){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.insertDishes(dishes)>0?true:false;
        message.setSuccess(flag);
        message.setMessage("添加成功");
        return message;
    }

    public ResponseMessage updateDishes(Dishes dishes){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.updateDishes(dishes)>0?true:false;
        message.setSuccess(flag);
        message.setMessage("修改成功");
        return message;
    }

    public ResponseMessage deleteDishes(String dNumber){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.deleteDishes(dNumber)>0?true:false;
        message.setSuccess(flag);
        message.setMessage("删除成功");
        return message;
    }

    public ResponseMessage onSaleDishes(String dNumber){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.onSaleDishes(dNumber)>0?true:false;
        message.setSuccess(flag);
        message.setMessage("上架成功");
        return message;
    }

    public ResponseMessage offShelfDishes(String dNumber){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.offShelfDishes(dNumber)>0?true:false;
        message.setSuccess(flag);
        message.setMessage("下架成功");
        return message;
    }

    public ResponseMessage selectDishesListByExample(Dishes dishes){
        ResponseMessage message = new ResponseMessage();
        message.setData(mapper.selectDishesListByExample(dishes));
        message.setMessage("查询成功");
        message.setSuccess(true);
        message.setTotal(message.getData().size());
        return message;
    };
}
